<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Configuration extends Backend {

	public function __construct()
	{
		parent::__construct();

		$this->load->model("systemconfig_model");
		//
		$this->data['page_home']  = lang('lang_dashboard');
		$this->data['page_title'] = lang('lang_configuration');

		//
		$this->load->helper('form');
	}


	public function index()
	{
		// Title
		$this->data['meta_title'] = $this->data['page_title'];

		// Breadcrumbs
		$this->data['array_breadcrumbs'] = array(
			$this->data['page_home']  => 'backend',
			$this->data['page_title'] => 'backend/configuration'
		);

		//
		$this->data['content_header_title'] = content_header_title($this->data['page_title']);
		$this->data['content'] = 'configuration';

		//
		$this->render();
	}

	public function ship()
	{

		// Title
		$this->data['meta_title'] = $this->data['page_title'];

		// Breadcrumbs
		$this->data['array_breadcrumbs'] = array(
			$this->data['page_home']  => 'backend',
			$this->data['page_title'] => 'backend/configuration'
		);


		$this->data['message_admin']        = (validation_errors()) ? validation_errors() : NULL;

		$config = $this->systemconfig_model->get_configs(); 
		$this->data["config"]=$config;


		$this->form_validation->set_rules('shiptype', '物流类型', 'required');
		if ($this->form_validation->run() == TRUE)
		{

			$data = array(
				'shiptype'         => trim($this->input->post('shiptype')),
				'sfapiid'         =>  trim($this->input->post('sfapiid')),
				'sfapikey'         =>  trim($this->input->post('sfapikey')),
				'trackapikey'         =>  trim($this->input->post('trackapikey')),
				'defsendercom'         =>  trim($this->input->post('defsendercom')),
				'defsendername'         =>  trim($this->input->post('defsendername')),
				'defsenderphone'         =>  trim($this->input->post('defsenderphone')),
				'defsenderprovince'         =>  trim($this->input->post('defsenderprovince')),
				'defsendercity'         =>  trim($this->input->post('defsendercity')),
				'defsenderaddress'         =>  trim($this->input->post('defsenderaddress')),
				'defsenderpost'         =>  trim($this->input->post('defsenderpost')),

			);
			$this->systemconfig_model->update_config($data);
			
			redirect('backend/configuration/ship', 'refresh');
		}else{
			if(validation_errors())
				
			$this->data['noticevalue']=$this->form_validation->set_value('notice');
		}


		$sfapiid = array(
			'name'      => 'sfapiid',
			'id'        => 'sfapiid',
			'value'     =>  isset($config["sfapiid"])?$config["sfapiid"]:"",
			'class'     =>  'form-control input-sm',
			'placeholder'=> '请输入顺丰API ID',
			'maxlength' => '100'
		);
		$this->data["sfapiid"]=$sfapiid;

		$sfapikey = array(
			'name'      => 'sfapikey',
			'id'        => 'sfapikey',
			'value'     =>  isset($config["sfapikey"])?$config["sfapikey"]:"",
			'class'     =>  'form-control input-sm',
			'placeholder'=> '请输入顺丰API KEY',
			'maxlength' => '100'
		);
		$this->data["sfapikey"]=$sfapikey;



		$trackapikey = array(
			'name'      => 'trackapikey',
			'id'        => 'trackapikey',
			'value'     =>  isset($config["trackapikey"])?$config["trackapikey"]:"",
			'class'     =>  'form-control input-sm',
			'placeholder'=> '请输入TrackingMore API KEY',
			'maxlength' => '100'
		);
		$this->data["trackapikey"]=$trackapikey;
		


		$defsendercom = array(
			'name'      => 'defsendercom',
			'id'        => 'defsendercom',
			'value'     =>  isset($config["defsendercom"])?$config["defsendercom"]:"",
			'class'     =>  'form-control input-sm',
			'placeholder'=> '请输入默认寄件人公司',
			'maxlength' => '100'
		);
		$this->data["defsendercom"]=$defsendercom;
		$defsendername = array(
			'name'      => 'defsendername',
			'id'        => 'defsendername',
			'value'     =>  isset($config["defsendername"])?$config["defsendername"]:"",
			'class'     =>  'form-control input-sm',
			'placeholder'=> '请输入默认寄件人姓名',
			'maxlength' => '100'
		);
		$this->data["defsendername"]=$defsendername;
		$defsenderphone = array(
			'name'      => 'defsenderphone',
			'id'        => 'defsenderphone',
			'value'     =>  isset($config["defsenderphone"])?$config["defsenderphone"]:"",
			'class'     =>  'form-control input-sm',
			'placeholder'=> '请输入默认寄件人手机号',
			'maxlength' => '100'
		);
		$this->data["defsenderphone"]=$defsenderphone;
		$defsenderprovince = array(
			'name'      => 'defsenderprovince',
			'id'        => 'defsenderprovince',
			'value'     =>  isset($config["defsenderprovince"])?$config["defsenderprovince"]:"",
			'class'     =>  'form-control input-sm',
			'placeholder'=> '请输入默认寄件人省',
			'maxlength' => '100'
		);
		$this->data["defsenderprovince"]=$defsenderprovince;
		$defsendercity = array(
			'name'      => 'defsendercity',
			'id'        => 'defsendercity',
			'value'     =>  isset($config["defsendercity"])?$config["defsendercity"]:"",
			'class'     =>  'form-control input-sm',
			'placeholder'=> '请输入默认寄件人城市',
			'maxlength' => '100'
		);
		$this->data["defsendercity"]=$defsendercity;
		$defsenderaddress = array(
			'name'      => 'defsenderaddress',
			'id'        => 'defsenderaddress',
			'value'     =>  isset($config["defsenderaddress"])?$config["defsenderaddress"]:"",
			'class'     =>  'form-control input-sm',
			'placeholder'=> '请输入默认寄件人地址',
			'maxlength' => '100'
		);
		$this->data["defsenderaddress"]=$defsenderaddress;
		$defsenderpost = array(
			'name'      => 'defsenderpost',
			'id'        => 'defsenderpost',
			'value'     =>  isset($config["defsenderpost"])?$config["defsenderpost"]:"",
			'class'     =>  'form-control input-sm',
			'placeholder'=> '请输入默认寄件人邮编',
			'maxlength' => '100'
		);
		$this->data["defsenderpost"]=$defsenderpost;




		$this->data['tab'] = 'ship';
		
		$this->data['content_header_title'] = content_header_title($this->data['page_title']);
		$this->data['content'] = 'basic_setting';

		//
		$this->render();

	}
	public function basic()
	{
		// Title
		$this->data['meta_title'] = $this->data['page_title'];

		// Breadcrumbs
		$this->data['array_breadcrumbs'] = array(
			$this->data['page_home']  => 'backend',
			$this->data['page_title'] => 'backend/configuration'
		);


		$this->data['message_admin']        = (validation_errors()) ? validation_errors() : NULL;

		$config = $this->systemconfig_model->get_configs(); 
		$this->data['remove_keywordvalue']= isset($config["remove_keyword"])?$config["remove_keyword"]:'';
		$this->data['remove_dotvalue']= isset($config["remove_dot"])?$config["remove_dot"]:'';
		$this->data['expresscategory_val']= isset($config["expresscategory"])?$config["expresscategory"]:'';

		$this->data['remove_keyword'] = array(
			'name'  => 'remove_keyword',
			'id'    => 'remove_keyword',
			'class' => 'form-control',
				
		);
		$this->data['remove_dot'] = array(
			'name'  => 'remove_dot',
			'id'    => 'remove_dot',
			'class' => 'form-control',
				
		);
		$this->data['expresscategory'] = array(
			'name'  => 'expresscategory',
			'id'    => 'expresscategory',
			'class' => 'form-control',
				
		);
		

		$apikey = array(
			'name'      => 'apikey',
			'id'        => 'apikey',
			'value'     =>  isset($config["apikey"])?$config["apikey"]:"",
			'class'     =>  'form-control input-sm',
			'placeholder'=> '请输入谷歌翻译密钥',
			'maxlength' => '100'
		);
		$this->data["apikey"]=$apikey;


		$vultr = array(
			'name'      => 'vultr',
			'id'        => 'vultr',
			'value'     =>  isset($config["vultr"])?$config["vultr"]:"",
			'class'     =>  'form-control input-sm',
			'placeholder'=> '请输入Vultr密钥',
			'maxlength' => '100'
		);
		$this->data["vultr"]=$vultr;



		$urlpath = array(
			'name'      => 'urlpath',
			'id'        => 'urlpath',
			'value'     =>  isset($config["urlpath"])?$config["urlpath"]:"",
			'class'     =>  'form-control input-sm',
			'placeholder'=> '请输入图片url路径,最后不用带/',
			'maxlength' => '100'
		);
		$this->data["urlpath"]=$urlpath;



		$this->form_validation->set_rules('remove_dot', '其它废词', 'required');
		$this->form_validation->set_rules('remove_keyword', '英文废词', 'required');

		if ($this->form_validation->run() == TRUE)
		{

			$data = array(
				'remove_keyword'         => trim($this->input->post('remove_keyword')),
				'remove_dot'         =>  trim($this->input->post('remove_dot')),
				'apikey'         =>  trim($this->input->post('apikey')),
				'urlpath'         =>  trim($this->input->post('urlpath')),
				'expresscategory' =>  trim($this->input->post('expresscategory')),
				'vultr' =>  trim($this->input->post('vultr')),

			);

			$this->systemconfig_model->update_config($data);
			
			redirect('backend/configuration/basic', 'refresh');
		}else{
			if(validation_errors())
				
			$this->data['noticevalue']=$this->form_validation->set_value('notice');
		}
		
		$this->data['content_header_title'] = content_header_title($this->data['page_title']);
		$this->data['content'] = 'basic_setting';

		$this->data['tab'] = 'common';
		//
		$this->render();


	}

	public function Interface($section = 'adm')
	{
		if ($section == 'adm')
		{
			$this->data['status_adm'] = 'active';
			$this->data['status_pub'] = 'no-active';
		}
		elseif ($section == 'pub')
		{
			$this->data['status_adm'] = 'no-active';
			$this->data['status_pub'] = 'active';
		}
		else
		{
			redirect('backend');
		}

		//
		$subtitle = lang('lang_interface');

		// Breadcrumbs
		$this->data['array_breadcrumbs'] = array(
			$this->data['page_home']  => 'backend',
			$this->data['page_title'] => 'backend/configuration',
			$subtitle                 => 'backend/configuration/interface'
		);

		//
		$this->data['content_header_title'] = content_header_title($this->data['page_title'], $subtitle);
		$this->data['content'] = 'configuration/interface';

		//
		$this->render();
	}
}
